#include "Eventfd.hpp"
#include <func.h>
#include <thread>
#include <iostream>

using std::cout;
using std::endl;
using std::thread;

struct MyTask{
    void process(){
        srand(time(nullptr));
        int num = rand() % 100;
        cout << "sub thread create a num : " << num << endl;
    }
};

int main()
{
    ln::Eventfd eventfd(std::bind(&MyTask::process,MyTask()));

    //创建子线程，并执行Eventfd的start函数
    thread th(std::bind(&ln::Eventfd::start,&eventfd));
    
    int cnt = 10;
    while(cnt-- > 0){
        //主线程唤醒子线程执行任务
        eventfd.wakeup();

        sleep(1);
        cout << "main thread " << cnt << endl;
    }
    eventfd.stop();

    //主线程等待子线程
    th.join();

    return 0;
}

